/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "材质.h"

static C_Key分配器 g材质ID;

//S_设备环境& ctx
S_材质* f_material_createPBR() {
	S_材质* mat = new S_材质();

	mat->m_光追材质ID = g材质ID.f_Gen();


	S_Material rayMaterial{};
	rayMaterial.m_color = { 1.0f, 0.0f, 0.8f };	
	rayMaterial.m_colorTex = -1;

	rayMaterial.m_emission = {};				//发光
	rayMaterial.m_emissionTex = -1;
			   
	rayMaterial.m_reflect = 0;					//反射度
	rayMaterial.m_reflectTex = -1;

	rayMaterial.m_refract = 0;					//折射
	rayMaterial.m_refractTex = -1;

	rayMaterial.m_roughness = 0.5;				//粗糙度
	rayMaterial.m_roughnessTex = -1;

	rayMaterial.m_alpha = 1;
	rayMaterial.m_alphaTex = -1;

	rayMaterial.m_normalTex = -1;
	

	rayMaterial.m_transmission = 0;


	rayMaterial.m_shaderIndex = -1;
	rayMaterial.m_LigthMask = 1;
	
	if (mat->m_光追材质ID >= S_光追后端::m_材质->m_Size) {
		f_buf_resize(S_光追后端::m_材质, mat->m_光追材质ID + 1);
	}
	f_buf_set(S_光追后端::m_材质, mat->m_光追材质ID, rayMaterial);

	//mat->m_光追材质 = buf;
	return mat;
}

void f_material_releasePBR(S_材质* mat) {
	g材质ID.f_Move(mat->m_光追材质ID);
	//f_buf_release板载缓存(mat->m_光追材质);
	delete mat;
}














